@extends('main')

@section('tip', '发表的博文')

@section('content')
<div class="row">
    <div>
        <div class="col-md-6"><h2>博文列表</h2></div>
        <div class="col-md-6">{!! Html::linkRoute('post.create', '创建博文', null, ['class'=>'btn btn-primary', 'style'=>'margin-top:18px']) !!}</div>
    </div>
    <table class="table table-hover">
        <thead>
            <tr>
            <th> 博文 ID </th>
            <th> 标题 </th>
            <th> 内容简介 </th>
            <th> 创建时间 </th>
            <th> 操作 </th>
            </tr>
        </thead>
        <tbody>
            @foreach($posts as $post)
            <tr>
                <td style="vertical-align: middle">{{ $post->id }}</td>
                <td style="vertical-align: middle">{{ $post->title }}</td>
                <td style="vertical-align: middle; max-width:430px">
                    <?php $body = strip_tags($post->body) ?>
                    {!! mb_substr($body, 0, 50) !!}
                    {!! mb_strlen($body)>50?'...':'' !!}</td>
                <td style="vertical-align: middle">{{ $post->created_at }}</td>
                <td style="vertical-align: middle">
                    <a href="{{ route('post.show', $post->id) }}" class="btn btn-default btn-sm">预览</a>
                    <a href="{{ route('post.edit', $post->id) }}" class="btn btn-default btn-sm">修改</a>
                </td>
            </tr>
            @endforeach
        </tbody>
    </table>
    <div class="text-center">
        {!! $posts->render() !!}
    </div>
</div>
@endsection
